<?php

namespace Maestros\Controller\Service;

use Zend\Db\Adapter\Adapter;
use Componentes\Controller\UtilsArrayController;
use Maestros\Model\Entity\EstadoAlumno;
use Maestros\Controller\Service\GenericService;
use Maestros\Model\Dao\EstadoAlumnoDAO;
use DateTime;
use DateTimeZone;
use Inscripcion\Controller\Service\ControlInscripcionService;

//SERVICIO
class EstadoAlumnoService extends GenericService {

    /**
     * @var Zend\Db\Adapter\Adapter 
     */
    private $dbAdapter;
    private static $estadoAlumnoService;

    /**
     * @param \Zend\Db\Adapter\Adapter $dbAdapter
     */
    private function __construct(Adapter $dbAdapter) {
        $this->dbAdapter = $dbAdapter;
    }

    public static function getInstance($adapter) {
        if (self::$estadoAlumnoService == null) {
            self::$estadoAlumnoService = new EstadoAlumnoService($adapter);
        }
        return self::$estadoAlumnoService;
    }

    public function getEstadoAlumnoDao() {
        return EstadoAlumnoDAO::getInstance($this->dbAdapter);
    }

    /**
     * @param type $id
     * @return type
     */
    public function getRegistro($id) {
        $data = null;
        $success = false;
        $estadoAlumno = $this->obtenerEstadoAlumnoSegunId($id);
        if ($estadoAlumno->getId() != null) {
            $data[0] = $estadoAlumno->objectToArray();
            $success = true;
        }
        return UtilsArrayController::organizarOutput($success, $data, null);
    }

    public function obtenerEstadoAlumnoSegunId($id) {
        $registros = $this->getEstadoAlumnoDao()->getRegistro($id);
        $data = UtilsArrayController::llenarData($registros);
        $estadoAlumno = new EstadoAlumno($data[0]);
        return $estadoAlumno;
    }

}
